#include "Application.h"
#include <stdio.h>
#include <unistd.h>

Application* Application::g_applicationInstance=NULL;
Application::Application()
{
    if (g_applicationInstance==NULL)
    {
        g_applicationInstance=this;
    }
    else
    {
        printf("ERROR: More Than One AppDelegate Instance In System!!!\n");
        while(1);  
    }
    m_appStatus=APP_STATUS_IDLE;
}
Application::~Application()
{
}
Application* Application::getInstance()
{
    if(g_applicationInstance==NULL)
    {
        printf("ERROR: No AppDelegate Instance In System!!!\n");
        while(1);
    }
    return g_applicationInstance;
}

int Application::run()
{
    if (g_applicationInstance==NULL)
    {
        printf("ERROR: No AppDelegate Instance In System!!!\n");
        return -1;
    }
    applicationLauching();
    while(1)
    {
        if (m_appStatus==APP_STATUS_EXIT)
        {
            applicationWillExit();
            return -1;
        }
        else
        {
            sleep(0);
        }
    }
    return 0;
}